#include "stdio.h"

void sort(double *tmp_nums, int *nums, int numsSize) {
    for (int i = 0; i < numsSize; ++i) {
        for (int j = i; j < numsSize; ++j) {
            if (nums[i] < nums[j]) {
                int tmp = nums[j];
                nums[j] = nums[i];
                nums[i] = tmp;
            }
        }
    }
    for (int i = 0; i < numsSize; ++i) {
        tmp_nums[i] = nums[i] * 1.0;
    }
}

void sort_double(double *nums, int numsSize) {
    for (int i = 0; i < numsSize; ++i) {
        for (int j = i; j < numsSize; ++j) {
            if (nums[i] < nums[j]) {
                double tmp = nums[j];
                nums[j] = nums[i];
                nums[i] = tmp;
            }
        }
    }
}

int halveArray(int* nums, int numsSize){
    double count = 0;
    for (int i = 0; i < numsSize; ++i) {
        count += nums[i];
    }

    double tmp_nums[numsSize];
    sort(tmp_nums, nums, numsSize);
    double tmp = count / 2;
    int ret = 0;
    while (tmp < count) {
        count -= (double)tmp_nums[0] / 2;
        tmp_nums[0] =  (double)tmp_nums[0] / 2;
        printf("%f\n", tmp_nums[0]);
        sort_double(tmp_nums, numsSize);
        ret++;
    }
    return ret;
}

int main()
{
    int test[4] = {5,19,8,1};
    int ret = halveArray(test, 4);
    printf("%d", ret);
}